import unittest
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
from ddt import ddt, data, unpack
from util.read_csv import CSVUtil

filePath = "..\\testdata\\testdata2.csv"
u = CSVUtil(filePath)
d = u.get_list_data()
print(d)


@ddt
class MyTestCase(unittest.TestCase):
    def setUp(self) -> None:
        self.driver = webdriver.Chrome(r'C:\Program Files\Google\Chrome\Application\chromedriver.exe')
        self.driver.implicitly_wait(15)

    def tearDown(self) -> None:
        sleep(3)
        self.driver.quit()

    @data(*d)
    @unpack
    def test_something(self, email, title, content):
        self.driver.get("http://127.0.0.1/upload/message.php")
        self.driver.find_element(By.NAME, "user_email").send_keys(email)
        self.driver.find_element(By.NAME, "msg_title").send_keys(title)
        self.driver.find_element(By.NAME, "msg_content").send_keys(content)
        self.driver.find_element(By.XPATH, "//input[@value='我要留言']").click()


if __name__ == '__main__':
    unittest.main()
